@use "../abstracts/mixins";

.jenkins-table {
  --table-padding: 0.55rem;

  position: relative;
  width: 100%;
  background: var(--table-background);
  border-radius: calc(var(--table-border-radius) + 4px);
  border: 4px solid var(--table-background);
  border-bottom-width: 2px;
  border-spacing: 0 2px;
  background-clip: padding-box;
  margin-bottom: var(--section-padding);

  &::before {
    content: "";
    position: absolute;
    inset: -4px -4px -2px;
    border: var(--card-border-width) solid var(--table-border-color);
    border-radius: inherit;
    pointer-events: none;
  }

  * {
    -webkit-border-horizontal-spacing: 0;
    -webkit-border-vertical-spacing: 0;
  }

  & > thead {
    & > tr {
      & > th {
        color: var(--table-header-foreground);
        text-align: left;
        padding-top: calc(var(--table-padding) * 0.9);
        padding-bottom: calc((var(--table-padding) * 0.9) + 2px);
        padding-left: 1.6rem;
        font-weight: 500;
        font-size: 0.875rem;

        &[align="center"] {
          text-align: center;
        }

        &[align="right"] {
          text-align: right;
        }

        &:first-of-type {
          padding-left: calc(var(--table-padding) * 2);
        }

        &:last-of-type {
          padding-right: var(--table-padding);
        }

        a {
          color: var(--table-header-foreground);
          font-weight: 700;

          span.sortarrow {
            width: 24px;
          }
        }

        svg {
          vertical-align: middle;
          width: 0.8rem;
          height: 0.8rem;
        }
      }
    }
  }

  & > tbody {
    & > tr {
      color: var(--table-body-foreground);

      & > td {
        background: var(--table-body-background);
        vertical-align: middle;
        padding: var(--table-padding) 0 var(--table-padding) 1.6rem;
        height: 3rem;

        &:first-of-type {
          padding-left: calc(var(--table-padding) * 2);
        }

        &:last-of-type {
          padding-right: var(--table-padding);
        }
      }

      // Style the rows so that the first and last have a larger border radius
      & > td:first-of-type {
        border-top-left-radius: var(--table-row-border-radius);
        border-bottom-left-radius: var(--table-row-border-radius);
      }

      & > td:last-of-type {
        border-top-right-radius: var(--table-row-border-radius);
        border-bottom-right-radius: var(--table-row-border-radius);
      }

      // First row
      &:first-of-type {
        & > td:first-of-type {
          border-top-left-radius: var(--table-border-radius);
        }

        & > td:last-of-type {
          border-top-right-radius: var(--table-border-radius);
        }
      }

      // Last row
      &:last-of-type {
        & > td:first-of-type {
          border-bottom-left-radius: var(--table-border-radius);
        }

        & > td:last-of-type {
          border-bottom-right-radius: var(--table-border-radius);
        }
      }
    }
  }

  &__cell__button-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  &__cell--tight {
    padding-left: 0 !important;
    text-align: right !important;
    white-space: nowrap;
    width: 4rem;
  }

  &__cell--checkbox {
    padding: calc(var(--table-padding) * 2) !important;
    vertical-align: top !important;
    width: calc((var(--table-padding) * 2) + 22px);
  }

  &__cell--no-wrap {
    white-space: nowrap;
  }

  &__button {
    display: inline-flex;
  }

  &__link,
  .sortheader {
    display: inline-flex;
  }

  &__link {
    .jenkins-menu-dropdown-chevron {
      top: 0;
    }
  }

  .jenkins-button {
    margin: -10px 0;
    padding: 0.5rem 0.75rem;
    min-height: 1.75rem;

    // Increase the size of symbols compared to regular buttons
    svg {
      width: 1.5rem !important;
      height: 1.5rem !important;
    }
  }

  &__button,
  &__icon {
    svg,
    .build-status-icon__wrapper,
    img {
      width: 1.5rem !important;
      height: 1.5rem !important;
    }
  }

  &--medium {
    --table-padding: 0.4rem !important;

    tbody > tr > td {
      height: 40px;
    }

    .jenkins-table__button,
    .jenkins-table__link,
    .jenkins-table__icon {
      svg,
      .build-status-icon__wrapper,
      img {
        width: 1.3rem !important;
        height: 1.3rem !important;
      }
    }

    .jenkins-button {
      padding: 0.4rem 0.6rem;

      svg {
        width: 1.3rem !important;
        height: 1.3rem !important;
      }
    }
  }

  &--auto-width {
    width: auto !important;
  }

  &--small {
    --table-padding: 0.2rem;

    tbody > tr > td {
      height: 34px;
    }

    .jenkins-table__button,
    .jenkins-table__link,
    .jenkins-table__icon {
      svg,
      .build-status-icon__wrapper,
      img {
        width: 1rem !important;
        height: 1rem !important;
      }
    }

    .jenkins-button {
      padding: 0.3rem 0.5rem;

      svg {
        width: 1rem !important;
        height: 1rem !important;
      }
    }
  }

  &__button,
  &__link {
    color: var(--link-color);
  }

  &__button,
  .sortheader,
  &__link {
    @include mixins.item;

    align-items: center;
    justify-content: center;
    appearance: none;
    outline: none;
    border: none;
    margin: 0;
    padding: 0;
    cursor: pointer;
    color: inherit;
    font-weight: inherit;
    font-size: inherit;
    background: transparent;
    text-decoration: none !important;
    line-height: 1 !important;
    transition: var(--standard-transition);

    &::before,
    &::after {
      inset: -7px -10px;
      border-radius: 6px;
    }
  }

  &__badge {
    margin-left: 1rem !important;

    &::before {
      inset: -5px -8px;
      border-radius: 13px;
      background: currentColor;
      opacity: 0.05;
    }

    &::after {
      inset: -5px -8px;
      box-shadow: 0 0 0 10px currentColor;
      opacity: 0;
    }

    &:hover {
      &::before {
        background: currentColor;
        border-radius: 6px;
      }
    }

    &:active,
    &:focus {
      &::before {
        background: currentColor;
        border-radius: 6px;
      }

      &::after {
        box-shadow: 0 0 0 5px currentColor;
        opacity: 0.025;
      }
    }
  }
}
